$(function () {
    initNav()
    var userid = getCookie("userid")
    var token = getCookie("token")
    function init() {
        var options = {
            url: "http://127.0.0.1:8888/cart/list",
            type: "GET",
            data: {
                id: userid
            },
            headers: {
                authorization: token
            },
            dataType: "json"
        }
        $.ajax(options)
            .done(function (res) {
                render(res)
            })
    }
    function render(res){
        $(".cart-container").html(
            res.cart.map(item=>
                `
                <div class="goods">
                <div class="goods">
                    <div class="p-goods">
                        <div class="p-img">
                            <img src=${item.img_small_logo}
                                alt="">
                        </div>
                        <div class="p-item">
                            ${item.title}
                        </div>
                    </div>
                    <div class="p-price">￥${item.price}</div>
                    <div class="p-quantity">
                        <div class="cartnum">
                            <button>-</button>
                            <input type="text" value = ${item.cart_number}>
                            <button>+</button>
                        </div>
                    </div>
                    <div class="p-sum">￥${item.cart_number*item.price}</div>
                    <div class="p-options">
                        <a data-id=${item.goods_id} href="javascript:void(0)">删除</a>
                    </div>
                </div>
            </div>
       
                `
                ).join("")
        )
    }
    init()
})